// @ts-ignore
/* eslint-disable */
import {request} from 'umi';
import {ManageRuleBody, ManageRuleListItem} from './data';

export async function dataList(params: {
  // query
  /** 当前的页码 */
  current?: number;
  /** 页面的容量 */
  pageSize?: number;
}, sorter: any) {
  return request<{
    data: ManageRuleListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/v2/enterprise/manage-rule/list', {
    method: 'GET',
    params: {
      ...params,
      pageNum: params.current,
      // orderByColumn: 'createTime',
      // isAsc: 'desc',
      orderByColumn: Object.keys(sorter)[0],
      isAsc: Object.values(sorter)[0],
    },
  });
}

export async function loadData(param: ManageRuleBody): Promise<{ data: ManageRuleBody }> {
  return request(`/v2/enterprise/manage-rule/${param.ruleId}`, {method: 'GET'});
}

export async function addData(param: ManageRuleBody): Promise<{ data: number }> {
  return request('/v2/enterprise/manage-rule', {method: 'POST', data: param});
}

export async function dataInit(): Promise<{ data: number }> {
  return request('/v2/enterprise/manage-rule/init', {method: 'POST'});
}

export async function updateData(param: ManageRuleBody): Promise<{ data: number }> {
  return request('/v2/enterprise/manage-rule', {method: 'PUT', data: param});
}

export async function removeData(data: number[], options?: { [key: string]: any }) {
  return request<Record<string, any>>(`/v2/enterprise/manage-rule/` + data.join(), {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}
